<template>
  <v-card>
      <v-flex xs12 sm10>
        <v-tree url="/item/category/list"
                :isEdit="isEdit"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                @handleClick="handleClick"
        />
      </v-flex>
  </v-card>
</template>

<script>
  export default {
    name: "category",
    data() {
      return {
        isEdit:true
      }
    },
    methods: {
      handleAdd(node) {
        console.log(node)
        this.$http.post("/item/category/add",node).then((res)=>{
          let resData = res.data;
          this.$router.go(0)
        })
      },
      handleEdit(id, name) {
        console.log("edit... id: " + id + ", name: " + name)
        const data=
          {
            "id":id,
            "name":name
          }
        this.$http.post("/item/category/update",data
            ).then(()=>{

        })
      },
      handleDelete(id) {
        this.$http.delete("/item/category/del?id="+id).then((res)=>{

        })
      },
      handleClick(node) {
        if(node.path==node.name){
        }else {
          this.handleEdit(node.id, node.name)
        }
      }
    }
  };
</script>

<style scoped>

</style>
